package com.xw.lianshou.service;

import com.xw.lianshou.dao.IndexDao;
import com.xw.lianshou.utils.TransactionalUtil;
import com.xw.lianshou.zhujie.aop.ExtTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * 手动事物测试
 * @author xw
 * @date 2021/5/27 22:24
 */
@Service
public class Index_shouService {
    @Autowired
    private IndexDao indexDao;
    @Autowired
    private TransactionalUtil transactionalUtil;

//    @Transactional
    /*public String insert_shou(){
        TransactionStatus begin=null;
        try {
            String name = "xw";
            //先创建事物
            begin = transactionalUtil.begin();
            int j = indexDao.insert(name);
//            int i = j / 0;
            //事物提交
            transactionalUtil.commit(begin);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
            if (begin != null) {
                //出现错误 事物回滚
                transactionalUtil.rollback(begin);
            }
            return "fail";
        }
    }*/

    @ExtTransactional(name = "xw")
    public String insert_shou(){
        String name = "xw";
        int j = indexDao.insert(name);
        int i = j / 0;
        return "success";
    }
}
